package net.jwtools.tmt.service;

import java.util.List;


import net.jwtools.tmt.dao.hibernate.TerritoryHibernateDAO;
import net.jwtools.tmt.domain.Territory;
import net.jwtools.tmt.domain.Status;

/**
 * @author Naftali van der Loon
 * 
 * This service to Territorys
 */

public class TerritoryService implements TMTService {
	private TerritoryHibernateDAO dao;

	public void setDao(TerritoryHibernateDAO territoryHibernateDAO) {
		this.dao = territoryHibernateDAO;
	}

	public TerritoryHibernateDAO getDao() {
		return dao;
	}

	public List<Territory> getAllTerritories() {
		List<Territory> territories = null;
		territories = dao.findAll();
		return territories;
	}

	public Territory getFullTerritoryById(Long id) {
		Territory territory = null;
		territory = dao.findFullById(id);
		return territory;
	}
	
	public Territory getTerritoryById(Long id) {
		Territory territory = null;
		territory = dao.findById(id);
		return territory;
	}
	
	public Territory getTerritoryByNumber(Integer number) {
		Territory territory = null;
		territory = dao.findByNumber(number);
		return territory;
	}
	
	public void removeTerritory(Territory territory) {
		//TODO check if territory has outstanding territories
		territory.setStatus(Status.INACTIVE);
		dao.saveOrUpdate(territory);
	}
}
